#include<cstdio>
#include<cmath>
const int maxn=1010;
const double EPS=1e-10;
const double INF=0x7fffffff;
struct point 
{
	double x,y;
}a[maxn];
struct vector
{
	point start,end;
}b[maxn];
double g[maxn][maxn];

double multi(point p1,point p2,point p0)//P0P1 叉乘P0P2
{
	return (p1.x-p0.x)*(p2.y-p0.y)-(p2.x-p0.x)*(p1.y-p0.y);
}
double max(double x,double y){return x>y?x:y;}
double min(double x,double y){return x<y?x:y;}
double dist(point a,point b) //求两点距离 
{
    return sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
}
bool iscross(vector v1,vector v2)
{
	if(max(v1.start.x,v1.end.x)>=min(v2.start.x,v2.end.x)&&
	   max(v2.start.x,v2.end.x)>=min(v1.start.x,v1.end.x)&&
	   max(v1.start.y,v1.end.y)>=min(v2.start.y,v2.end.y)&&
	   multi(v2.start,v1.end,v1.start)*multi(v1.end,v2.end,v1.start)>EPS&&
	   multi(v1.start,v2.end,v2.start)*multi(v2.end,v1.end,v2.start)>EPS)
		return true;
	return false;
}
double  dijkstra(int u,int v,int n)
{
	double dis[1101];
	bool s[1101];
	for(int i=1;i<=n;i++)
	{
		if(i!=u)s[i]=0;
		else s[i]=1;
		dis[i]=g[i][u];
	}
	for(int k=1;k<=n-2;k++)
	{
		double w=INF;
		int m=u;
		for(int i=1;i<=n;i++)
		   if(!s[i]&&dis[i]<w){m=i;w=dis[i];}
		if(m!=u)s[m]=1;
		else return INF;
		//if(m==v)return ;
		//else return dis[v];
		for(int i=1;i<=n;i++)
			if(!s[i]&&dis[m]+g[m][i]<dis[i])
				dis[i]=dis[m]+g[m][i];
	}
	return dis[v];
}
int main()
{
	int n,pcount,line;
	a[1].x=0;a[1].y=5;
	while(scanf("%d",&n)&&n!=-1)
	{
		pcount=1;line=0;
		double x,y1,y2,y3,y4;
		for(int i=1;i<=n;i++)
		{
			scanf("%lf%lf%lf%lf%lf",&x,&y1,&y2,&y3,&y4);
			a[++pcount].x=x;a[pcount].y=y1;
			b[++line].end=a[pcount];
			b[line].start.x=x;b[line].start.y=0;
			a[++pcount].x=x;a[pcount].y=y2;
			b[++line].start=a[pcount];
			a[++pcount].x=x;a[pcount].y=y3;
			b[line].end=a[pcount];
			a[++pcount].x=x;a[pcount].y=y4;
			b[++line].start=a[pcount];
			b[line].end.x=x;b[line].end.y=10.0;
		}
		a[++pcount].x=10;a[pcount].y=5;
		for(int i=1;i<pcount;i++)
			for(int j=i+1;j<=pcount;j++)
			{
				bool f=true;
				for(int k=1;k<=line;k++)
				{
					vector tem;
					tem.start=a[i];tem.end=a[j];
					if(iscross(tem,b[k]))
					{
						g[i][j]=g[j][i]=INF;
						f=false;
						break;
					}
				}
				if(f)g[i][j]=g[j][i]=dist(a[i],a[j]);
			}
		printf("%0.2lf\n",dijkstra(1,pcount,pcount));
	}
	return 0;
}



